package com.zoo.diannaopeijian.controller.export;

import com.zoo.diannaopeijian.comm.page.Page;
import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.Entryitem;
import com.zoo.diannaopeijian.domain.Entryrecord;
import com.zoo.diannaopeijian.domain.ExportItem;
import com.zoo.diannaopeijian.service.EntryrecordService;
import com.zoo.diannaopeijian.service.ExportItemService;
import com.zoo.diannaopeijian.service.ExportRecordService;
import com.zoo.diannaopeijian.service.ExportService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.misc.Contended;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by zx583 on 2018-01-28.
 */
@Controller
@RequestMapping("/export")
public class ExportController extends BaseController {
    @Resource
    private ExportService exportService;
    @Resource
    private ExportRecordService exportRecordService;
    @Resource
    private ExportItemService exportItemService;

    @RequestMapping("exportPage")
    public String exportPageRoute() {
        return "export/exportPage";
    }

    @RequestMapping("ReexportPage")
    public String ReexportPageRoute() {
        return "export/ReexportPage";
    }

    @RequestMapping("exportRecordPage")
    public String exportRecordPageRoute() {
        return "/export/exportRecordPage";
    }

    @RequestMapping("exportItemPage")
    public String exportItemPageRoute() {
        return "/export/exportItemPage";
    }

    @RequestMapping(value = "/exportWares")
    @ResponseBody
    public String EntryWares(@RequestBody List<ExportItem> exportItems) {
        return exportService.exportWares(getLoginId(), exportItems) ? success : fail;
    }

    @RequestMapping(value = "/ReexportWares")
    @ResponseBody
    public String ReexportWares(@RequestBody List<ExportItem> exportItems) {
        return exportService.ReexportWares(exportItems) ? success : fail;
    }

    @RequestMapping("/getExportRecord")
    @ResponseBody
    public Map getExportRecord(Page page, @DateTimeFormat(pattern  = "yyyy-MM-dd") Date from, @DateTimeFormat(pattern  = "yyyy-MM-dd") Date to, String staffname) {
        return buildPageResult(exportRecordService.getExportRecordWithPage(from, to, staffname, page));
    }

    @RequestMapping("/getExportItems")
    @ResponseBody
    public List getExportItems(Integer exportrecordid) {
        return exportItemService.getExportItemsByRecordId(exportrecordid);
    }
}
